package com.sdhs.costcontrol.controller;

import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.sdhs.common.annotation.Log;
import com.sdhs.common.core.controller.BaseController;
import com.sdhs.common.core.domain.AjaxResult;
import com.sdhs.common.core.page.TableDataInfo;
import com.sdhs.common.enums.BusinessType;
import com.sdhs.common.utils.poi.ExcelUtil;
import com.sdhs.costcontrol.domain.GcControlManagementCostMaintenance;
import com.sdhs.costcontrol.service.IGcControlManagementCostMaintenanceService;

/**
 * 管理成本维护Controller
 * 
 * @author wanglei
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/costcontrol/manageCost")
public class GcControlManagementCostMaintenanceController extends BaseController
{
    @Autowired
    private IGcControlManagementCostMaintenanceService gcControlManagementCostMaintenanceService;

    /**
     * 查询管理成本维护列表
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:manageCost:list')")
    @GetMapping("/list")
    public TableDataInfo list(GcControlManagementCostMaintenance gcControlManagementCostMaintenance)
    {
        startPage();
        List<GcControlManagementCostMaintenance> list = gcControlManagementCostMaintenanceService.selectGcControlManagementCostMaintenanceList(gcControlManagementCostMaintenance);
        return getDataTable(list);
    }

    /**
     * 导出管理成本维护列表
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:manageCost:export')")
    @Log(title = "管理成本维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GcControlManagementCostMaintenance gcControlManagementCostMaintenance)
    {
        List<GcControlManagementCostMaintenance> list = gcControlManagementCostMaintenanceService.selectGcControlManagementCostMaintenanceList(gcControlManagementCostMaintenance);
        ExcelUtil<GcControlManagementCostMaintenance> util = new ExcelUtil<GcControlManagementCostMaintenance>(GcControlManagementCostMaintenance.class);
        util.exportExcel(response, list, "管理成本维护数据");
    }

    /**
     * 获取管理成本维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:manageCost:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(gcControlManagementCostMaintenanceService.selectGcControlManagementCostMaintenanceById(id));
    }

    /**
     * 新增管理成本维护
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:manageCost:add')")
    @Log(title = "管理成本维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GcControlManagementCostMaintenance gcControlManagementCostMaintenance)
    {
    	if (!gcControlManagementCostMaintenanceService.checkCostSum(gcControlManagementCostMaintenance)) {
            return error("累计费用不能超过管理成本上限");
        }
        return toAjax(gcControlManagementCostMaintenanceService.insertGcControlManagementCostMaintenance(gcControlManagementCostMaintenance));
    }

    /**
     * 修改管理成本维护
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:manageCost:edit')")
    @Log(title = "管理成本维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GcControlManagementCostMaintenance gcControlManagementCostMaintenance)
    {
    	if (!gcControlManagementCostMaintenanceService.checkCostSum(gcControlManagementCostMaintenance)) {
            return error("累计费用不能超过管理成本上限");
        }
        return toAjax(gcControlManagementCostMaintenanceService.updateGcControlManagementCostMaintenance(gcControlManagementCostMaintenance));
    }

    /**
     * 删除管理成本维护
     */
    @PreAuthorize("@ss.hasPermi('costcontrol:manageCost:remove')")
    @Log(title = "管理成本维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(gcControlManagementCostMaintenanceService.deleteGcControlManagementCostMaintenanceByIds(ids));
    }
}
